<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>通过JS修改CSS样式</title>
    <style>
        .box1 {
            width: 200px;
            height: 200px;
            background-color: #bfa;
            margin: 10px auto;
        }
        button{
            display: block;
            margin:50px auto;
            width: 60px;
            height: 40px;
            font-size: 10px;
            border-radius: 10px;
        }
    </style>
    <script>
        document.addEventListener("DOMContentLoaded", function () {
            const btn = document.querySelectorAll(".btn")[0]
            btn.addEventListener("click",function(){
                /* 
                    如果样式名中有-，则取消-，转而使用驼峰命名法。
                
                */
                const box1=document.querySelector(".box1")
                box1.style.width="400px"
                box1.style.height="400px"
                box1.style.backgroundColor="rgba(0,0,255,0.9)"
                box1.style.opacity="0.8"
            })
        })
    </script>
</head>

<body>
    <button class="btn">点我一下</button>
    <hr>
    <div class="box1"></div>
</body>

</html>